function editorRen(id) {

    editor.config.height = 500;
    editor.config.uploadImgServer = '/CenterInc/view_inc/upload.aspx?mode=1';
    editor.config.uploadImgMaxSize = 2 * 1024 * 1024; // 2M
    editor.config.uploadImgAccept = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
    editor.config.uploadImgMaxLength = 5;
    return editor;
}

function Post_articles(self) {
    button_disabled(self, 'loading', 1);
    layer.load(1, {
        shade: [0.1, '#fff'] //0.1透明度的白色背景
    });
    var title = $("#ArticleTitle").val();
    var content = editor.txt.html();
    var time = $("#ArticleDate").val();
    var catalog = $("#ArticleCatalog").val();
    var pay = $("#isPay:checked").val() === undefined ? 'off' : $("#isPay:checked").val();
    var price = $("#ArticlePrice").val() === undefined ? '' : $("#ArticlePrice").val();
    console.log(price);
    var PayContent = $("#ArticlePayContent").val() === undefined ? '' : $("#ArticlePayContent").val();
    var url = $("#ArticleImgUrl").val();
    var describe = $("#ArticleDescribe").val();
    if (NotEmpty(title, content, time, catalog, url, describe)) {
        layer.closeAll('loading');
        layer.msg("不能留空哦", {icon: 5});
        button_disabled(self, '发布文章', 2);
        layer.msg('不能留空哦', {icon: 5});
        return;
    }
    if (pay == 'open') {
        if (NotEmpty(price, PayContent)) {
            layer.closeAll('loading');
            button_disabled(self, '发布文章', 2);
            layer.msg('价格和收费内容不能为空哦', {icon: 5});
            return;
        }
    }
    layer.confirm('确认提交？', {
        btn: ['确认', '取消'] //按钮
    }, function () {
        $.post("/CenterInc/view_inc/Article_inc.aspx?mode=3",
            {
                title: title,
                content: content,
                time: time,
                catalog: catalog,
                price: price,
                PayContent: PayContent,
                url: url,
                describe: describe,
                pay: pay
            }, function (data) {
                if (data["error"] != undefined) {
                    layer.closeAll('loading');
                    button_disabled(self, '发布文章', 2);
                    layer.msg(data['error'], {icon: 5});
                    return;
                }
                layer.msg(data['msg'], {icon: 1});
                setTimeout("layer.closeAll('loading');window.location.reload()",2000);
            });
    });

}

function onSwitch() {
    form.on('switch(ispay)', function (data) {
        if (data.elem.checked) {
            $("#Article_Pay_window").removeClass("layui-hide");
            $("#ArticlePrice").removeClass("layui-hide");
            layer.msg('收费以开启，请输入价格和收费内容哦', {icon: 1});
        } else {
            $("#Article_Pay_window").addClass("layui-hide");
            $("#ArticlePrice").addClass("layui-hide");
        }
        console.log(data.elem); //得到checkbox原始DOM对象
        console.log(data.elem.checked); //开关是否开启，true或者false
        console.log(data.value); //开关value值，也可以通过data.elem.value得到
        console.log(data.othis); //得到美化后的DOM对象
    });
}

function priview_Img() {
    var url = $("#ArticleImgUrl").val();
    if (url.length == 0) {
        layer.msg('不能留空哦', {icon: 5});
        return;
    }
    $("#ArticleImgPriview").attr('src', url);
}

function Update_article(self) {
    button_disabled(self, 'loading', 1);
    layer.load(1, {
        shade: [0.1, '#fff'] //0.1透明度的白色背景
    });
    var article_id=location.search.match(/^[^article_id=]\b$|[^article_id=]\d+/g)[0];
    var title = $("#ArticleTitle").val();
    var content = editor.txt.html();
    var time = $("#ArticleDate").val();
    var catalog = $("#ArticleCatalog").val();
    var pay = $("#isPay:checked").val() === undefined ? 'off' : $("#isPay:checked").val();
    var price = $("#ArticlePrice").val() === undefined ? '' : $("#ArticlePrice").val();
    console.log(price);
    var PayContent = $("#ArticlePayContent").val() === undefined ? '' : $("#ArticlePayContent").val();
    var url = $("#ArticleImgUrl").val();
    var describe = $("#ArticleDescribe").val();
    console.log(article_id);
    if (NotEmpty(title, content, time, catalog, url, describe)) {
        layer.closeAll('loading');
        layer.msg("不能留空哦", {icon: 5});
        button_disabled(self, '更新文章', 2);
        layer.msg('不能留空哦', {icon: 5});
        return;
    }
    if (pay == 'open') {
        if (NotEmpty(price, PayContent)) {
            layer.closeAll('loading');
            button_disabled(self, '更新文章', 2);
            layer.msg('价格和收费内容不能为空哦', {icon: 5});
            return;
        }
    }
    layer.confirm('请确认是否更新文章？', {
        btn: ['确认', '取消'] //按钮
    }, function () {
        $.post("/CenterInc/view_inc/Article_inc.aspx?mode=4",
            {
                article_id:article_id,
                title: title,
                content: content,
                time: time,
                catalog: catalog,
                price: price,
                PayContent: PayContent,
                url: url,
                describe: describe,
                pay: pay
            }, function (data) {
                if (data["error"]!=undefined) {
                    layer.closeAll('loading');
                    button_disabled(self, '更新文章', 2);
                    layer.msg(data['error'], {icon: 5});
                    return;
                }
                layer.msg(data['msg'], {icon: 1});
                setTimeout("layer.closeAll('loading');window.location.reload()",2000);
            });
    });
}